package com.manli.api.controller.wechat;

import com.manli.api.base.annotation.Permissions;
import com.manli.api.pojo.*;
import com.manli.api.pojo.dingdanxia.TaobaoGoodsClassQueryCouponInfo;
import com.manli.api.pojo.dingdanxia.TaobaoGoodsClassQueryCouponList;
import com.manli.api.pojo.dingdanxia.TaobaoGoodsClassQueryCouponTkl;
import com.manli.api.service.WechatActivationCouponBatchService;
import com.manli.api.service.wechat.WechatPayService;
import com.manli.api.util.RedisUtil;
import com.manli.api.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "优惠券接口")
public class WeChatCouponMiniProgramController {
    @Autowired
    private WechatPayService wechatPayService;
    @Autowired
    private WechatActivationCouponBatchService wechatActivationCouponBatchService;

    //TODO  淘宝优惠券接口
    //由于直接返回的是淘宝的字段名，前端直接使用淘宝的字段名即可，不做处理
    @ApiOperation(value="获取淘宝商品分类", notes="获取淘宝商品分类")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/taobao/goodsClass")
    public Result goodsClass(HttpServletRequest request) throws Exception {
        return wechatPayService.goodsClass(request);
    }

    //由于直接返回的是淘宝的字段名，前端直接使用淘宝的字段名即可，不做处理
    /**
     * 这里分类名称和商品名都可以查询，就是个查询接口
     */
    @ApiOperation(value="根据淘宝商品分类或者商品名查询优惠券列表", notes="根据淘宝商品分类或者商品名查询优惠券列表")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/taobao/getCouponListByClass")
    public Result getCouponListByClass(@RequestBody TaobaoGoodsClassQueryCouponList t, HttpServletRequest request) throws Exception {
        return wechatPayService.getCouponListByClass(t);
    }

    /**
     * 商品名都可以查询
     */
    @ApiOperation(value="根据商品名查询优惠券列表", notes="根据商品名查询优惠券列表")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/taobao/getCouponListByGoodsName")
    public Result getCouponListByGoodsName(@RequestBody TaobaoGoodsClassQueryCouponList t, HttpServletRequest request) throws Exception {
        return wechatPayService.getCouponListByClass(t);
    }

    //由于直接返回的是淘宝的字段名，前端直接使用淘宝的字段名即可，不做处理
    @ApiOperation(value="根据淘宝商品id和优惠券码获取淘口令", notes="根据淘宝商品id和优惠券码获取淘口令")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/taobao/getCouponTklByGoodsId")
    public Result getCouponTklByGoodsId(@RequestBody TaobaoGoodsClassQueryCouponTkl t, HttpServletRequest request) throws Exception {
        return wechatPayService.getCouponTklByGoodsId(t);
    }

    //由于直接返回的是淘宝的字段名，前端直接使用淘宝的字段名即可，不做处理
    @ApiOperation(value="根据淘宝商品id获取优惠券详情", notes="根据淘宝商品id获取优惠券详情")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/taobao/getCouponInfoByGoodsId")
    public Result getCouponInfoByGoodsId(@RequestBody TaobaoGoodsClassQueryCouponInfo t, HttpServletRequest request) throws Exception {
        return wechatPayService.getCouponInfoByGoodsId(t);
    }

    //TODO  平台优惠券接口
    @ApiOperation(value="平台优惠券分类", notes="平台优惠券分类")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/mantaotao/getCouponClass")
    public Result getCouponClass1() throws Exception {
        return wechatPayService.getCouponClass1();
    }

    /**
     * 这里分类名称查询优惠券
     */
    @ApiOperation(value="平台分类名称查询优惠券", notes="平台分类名称查询优惠券")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/mantaotao/getCouponListByClass")
    public Result getCouponListByClass1(@RequestBody ManTaoTaoCouponsByClass t, HttpServletRequest request) throws Exception {
        return wechatPayService.getCouponListByClass1(t);
    }

    /**
     * 优惠券单条信息
     */
    @ApiOperation(value = "优惠券单条信息",notes = "优惠券单条信息")
    @RequestMapping(value="/coupon/mantaotao/getCouponInfoById")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result getCouponInfoById(@RequestBody ManTaoTaoCouponInfoById t){
        if(t.getId() == null){
            return ResultUtil.error(-1,"缺少优惠券批次id");
        }
        return wechatActivationCouponBatchService.getCouponInfoById(t.getId());
    }

    /**
     * 这里搜索名称查询优惠券
     */
    @ApiOperation(value="平台搜索名称查询优惠券", notes="平台搜索名称查询优惠券")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/mantaotao/getCouponListBySearch")
    public Result getCouponListBySearch(@RequestBody ManTaoTaoCouponsByKeyWord t, HttpServletRequest request) throws Exception {
        return wechatPayService.getCouponListBySearch(t);
    }

    /**
     * 这里领取优惠券
     */
    @ApiOperation(value="平台领取优惠券", notes="平台领取优惠券")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/mantaotao/getCoupon")
    public Result getCoupon(@RequestBody ManTaoTaoCouponsGet t, HttpServletRequest request) throws Exception {
        return wechatPayService.getCoupon(t,request);
    }

    /**
     * 自己的优惠券列表，这里是直接请求微信字段名要按微信的字段来
     */
    @ApiOperation(value="自己的优惠券列表", notes="自己的优惠券列表")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    @RequestMapping(value="/coupon/mantaotao/myCouponsList")
    public Result getCoupon(@RequestBody QueryParamsMyCoupons t,HttpServletRequest request) throws Exception {
        return wechatPayService.myCouponsList(t,request);
    }



}
